@inline function Base.signbit(x::Duration)
    return signbit(nanoseconds(x))
end

function Base.sign(x::Duration)
    return sign(nanoseconds(x))
end

function Base.abs(x::Duration)
    nanos = abs(nanoseconds(x))
    return Duration(nanos)
end

function Base.abs2(x::Duration)
    nanos = abs2(nanoseconds(x))
    return Duration(nanos)
end

function Base.:(-)(x::Duration)
    nanos = -nanoseconds(x)
    return Duration(nanos)
end

function Base.:(+)(x::Duration, y::Duration)
    nanos = nanoseconds(x) + nanoseconds(y)
    return Duration(nanos)
end

function Base.:(-)(x::Duration, y::Duration)
    nanos = nanoseconds(x) - nanoseconds(y)
    return Duration(nanos)
end

function Base.:(*)(x::I, y::Duration) where I<:Union{Int32, Int64}
    nanos = x * nanoseconds(y)
    return Duration(nanos)
end
function Base.:(*)(x::Duration, y::I) where I<:Union{Int32, Int64}
    nanos = y * nanoseconds(x)
    return Duration(nanos)
end

(Base.div)(x::Duration, y::I) where I<:Union{Int32, Int64} = div(nanoseconds(x), y)
(Base.fld)(x::Duration, y::I) where I<:Union{Int32, Int64} = fld(nanoseconds(x), y)
(Base.cld)(x::Duration, y::I) where I<:Union{Int32, Int64} = cld(nanoseconds(x), y)
(Base.mod)(x::Duration, y::I) where I<:Union{Int32, Int64} = mod(nanoseconds(x), y)
(Base.rem)(x::Duration, y::I) where I<:Union{Int32, Int64} = rem(nanoseconds(x), y)
(Base.divrem)(x::Duration, y::I) where I<:Union{Int32, Int64} = div(x,y), rem(x,y)
(Base.fldmod)(x::Duration, y::I) where I<:Union{Int32, Int64} = fld(x,y), mod(x,y)

(Base.div)(x::Duration, y::Duration) = div(nanoseconds(x), nanoseconds(y))
(Base.fld)(x::Duration, y::Duration) = fld(nanoseconds(x), nanoseconds(y))
(Base.cld)(x::Duration, y::Duration) = cld(nanoseconds(x), nanoseconds(y))
(Base.mod)(x::Duration, y::Duration) = mod(nanoseconds(x), nanoseconds(y))
(Base.rem)(x::Duration, y::Duration) = rem(nanoseconds(x), nanoseconds(y))
(Base.divrem)(x::Duration, y::Duration) = div(x,y), rem(x,y)
(Base.fldmod)(x::Duration, y::Duration) = fld(x,y), mod(x,y)


for P in [:Nanosecond, :Microsecond, :Millisecond,
          :Second, :Minute, :Hour, :Day, :Week,
          :Nanoseconds, :Microseconds, :Milliseconds,
          :Seconds, :Minutes, :Hours]
    @eval begin
        Base.:(+)(x::Duration, p::$P) = Duration(nanoseconds(x) + nanoseconds(p))
        Base.:(+)(p::$P, x::Duration) = Duration(nanoseconds(x) + nanoseconds(p))
        Base.:(-)(x::Duration, p::$P) = Duration(nanoseconds(x) - nanoseconds(p))
        Base.:(-)(p::$P, x::Duration) = Duration(nanoseconds(x) - nanoseconds(p))
        Base.isequal(x::Duration, p::$P) = isequal(nanoseconds(x), nanoseconds(p))
        Base.isequal(x::$P, p::Duration) = isequal(nanoseconds(x), nanoseconds(p))
        Base.isless(x::Duration, p::$P)  = isless(nanoseconds(x), nanoseconds(p))
        Base.isless(x::$P, p::Duration)  = isless(nanoseconds(x), nanoseconds(p))        
    end
end


for P in [:Month, :Year,
          :Months, :Quarters, :Years, :Decades, :Centuries]
    @eval begin
        Base.:(+)(x::Duration, p::$P) = TimeSpan(x) + p  
        Base.:(+)(p::$P, x::Duration) = TimeSpan(x) + p
        Base.:(-)(x::Duration, p::$P) = TimeSpan(x) - p
        Base.:(-)(p::$P, x::Duration) = p - TimeSpan(x)
        Base.isequal(x::Duration, p::$P) = isequal(months(TimeSpan(x)), months(p))
        Base.isequal(x::$P, p::Duration) = isequal(months(x), months(TimeSpan(p)))
        Base.isless(x::Duration, p::$P)  = isless(months(TimeSpan(x)), months(p))
        Base.isless(x::$P, p::Duration)  = isless(months(x), months(TimeSpan(p)))        
    end
end
